package com.verlet.springbootdemo.simple.nettyrpc;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * NettyRpc 返回结果
 *
 * @author Verlet
 * @date 2023-03-08 21:43
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RpcResult implements Serializable{

    /**
     * 请求id
     */
    private long requestId;

    /**
     * 返回结果
     */
    private Object result;

    /**
     * 返回异常信息
     */
    private Throwable cause;

    public RpcResult(long requestId, Object result) {
        this.requestId = requestId;
        this.result = result;
        this.cause = null;
    }

    @JsonIgnore
    public boolean isError() {
        return this.cause != null;
    }

}
